#ifndef MAINBOARD_H
#define MAINBOARD_H

#include <QGuiApplication>
#include <QtQuick/QQuickWindow>
#include <QtQuick/QQuickPaintedItem>
#include <QtQuick/QQuickView>
#include <QProcess>
#include <QString>
#include <QTimer>

#include <stdio.h>

#define GET_AND_SET(func, firstFunc, name, type) \
    type func() const { return name; } \
    void set##firstFunc(const type &func) { name = func; }

enum {
    PLAY,
    PAUSE,
    STOP,
    READY,
};

enum {
    UNMUTE,
    MUTE,
};

enum {
    MAX_WINDOW,
    MIN_WINDOW,
};

class MainBoard : public QQuickPaintedItem
{
    Q_OBJECT
    Q_PROPERTY(int playerStatus READ playerStatus WRITE setPlayerStatus)
    Q_PROPERTY(int muteStatus READ muteStatus WRITE setMuteStatus)
    Q_PROPERTY(int windowStatus READ windowStatus WRITE setWindowStatus)
    Q_PROPERTY(float volumeValue READ volumeValue WRITE setVolumeValue)
    Q_PROPERTY(float volumeLength READ volumeLength WRITE setVolumeLength)
    Q_PROPERTY(float timeLength READ timeLength WRITE setTimeLength)
    Q_PROPERTY(float timeValue READ timeValue WRITE setTimeValue)
    Q_PROPERTY(float processLength READ processLength WRITE setProcessLength)
    Q_PROPERTY(float processValue READ processValue WRITE setProcessValue)
    Q_PROPERTY(int screenWidth READ screenWidth WRITE setScreenWidth)
    Q_PROPERTY(int screenHeight READ screenHeight WRITE setScreenHeight)

    Q_PROPERTY(QString movieFilePath READ movieFilePath WRITE setMovieFilePath)

public:
    GET_AND_SET(playerStatus, PlayerStatus, player_status, int)
    GET_AND_SET(muteStatus, MuteStatus, mute_status, int)
    GET_AND_SET(windowStatus, WindowStatus, window_status, int)
    GET_AND_SET(volumeValue, VolumeValue, volume_value, float)
    GET_AND_SET(volumeLength, VolumeLength, volume_length, float)
    GET_AND_SET(timeLength, TimeLength, time_length, float)
    GET_AND_SET(timeValue, TimeValue, time_value, float)
    GET_AND_SET(processLength, ProcessLength, process_length, float)
    GET_AND_SET(processValue, ProcessValue, process_value, float)
    GET_AND_SET(screenWidth, ScreenWidth, screen_width, int)
    GET_AND_SET(screenHeight, ScreenHeight, screen_height, int)
    GET_AND_SET(movieFilePath, MovieFilePath, movie_file_path, QString)

public:
    MainBoard(QQuickItem *parent = 0);
    ~MainBoard();
    void read_config_from_file();
    void paint(QPainter *painter);
    void SetQuickView(QQuickView *view) { m_view = view; }

signals:
    void process_value_changed(float value);
    void disvisible_all_widget();
    void process_finished(int exitCode);
public slots:
    void player_timer_out();

public:
    /* player widget slots */
    Q_INVOKABLE void play_pause_btn_click_slots();
    Q_INVOKABLE void stop_btn_click_slots();
    Q_INVOKABLE void mute_btn_click_slots();
    Q_INVOKABLE void volume_slider_valuechanged_slots(float value);
    Q_INVOKABLE void process_slider_valuechanged_slots(float value);
    Q_INVOKABLE void close_btn_click_slots();
    Q_INVOKABLE void max_btn_click_slots();
    Q_INVOKABLE void min_btn_click_slots();
    Q_INVOKABLE void set_btn_click_slots();
    Q_INVOKABLE void resize_player_window();
    Q_INVOKABLE void read_process_back_message();
//    Q_INVOKABLE void set_old_control_widget_length(float now_pos, float length);

private:
    /* player params */
    int player_status;
    int mute_status;
    int window_status;

    float volume_value;
    float volume_length;
    float time_length;
    float time_value;
    float process_length;
    float process_value;
    QString movie_file_path;

    /* mplayer process */
    QProcess player_process;

    int screen_width;
    int screen_height;
    QQuickView *m_view;

    QTimer *player_timer;
};

#endif // MAINWINDOW_H
